package com.mavet.demo.jdbcdemo1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Hello world!
 *
 */
public class AppSelect {
	public static void main(String[] args) {
		
		String url = "jdbc:mysql://localhost:3306/jdbcdemo";
		String username = "root";
		String password = "soft";
		Connection conn = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}

		String name = "";
		try {
			conn = DriverManager.getConnection(url, username, password);
			PreparedStatement ps = null;
			ResultSet rs = null;

			String sql = "select id,name,password from user where name like ?";
			ps = conn.prepareStatement(sql);
			ps.setString(1, "%" + name + "%");
			rs = ps.executeQuery();

			while (rs.next()) {
				System.out.print("id:" + rs.getInt("id") + "  ");
				System.out.print("name:" + rs.getString("name") + "  ");
				System.out.print("password:" + rs.getString("password"));
				System.out.println();

			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
